package myzzyl.controller;



import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import myzzyl.domain.dto.FloorDto;
import myzzyl.domain.dto.RoomTypeDto;
import myzzyl.domain.pojo.Floor;
import myzzyl.domain.pojo.RoomType;
import myzzyl.domain.vo.RoomTypeVo;
import myzzyl.mapper.RoomMapper;
import myzzyl.response.BaseResponse;
import myzzyl.response.PageResponse;
import myzzyl.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/roomTypes")
@Tag(name = "房型相关")
@Slf4j
public class RoomTypeController {

    @Autowired
    private RoomTypeService roomTypeService;

    /**
     * 获取所有房型
     */
    @GetMapping
    public BaseResponse<List<RoomTypeVo>> getAll() {
        log.info("分页获取所有房型");
        List<RoomTypeVo> floorList = roomTypeService.getAll();
        return BaseResponse.success(floorList);
    }

    /**
     * 获取房型详情
     */
    @GetMapping("/{id}")
    public BaseResponse<RoomTypeVo> getInfo(@PathVariable Long id) {
        log.info("获取房型详情:{}", id);
        return BaseResponse.success(roomTypeService.getInfo(id));
    }


    /**
     * 新增房型
     */
    @PostMapping
    public BaseResponse<Boolean> add(@RequestBody RoomTypeDto roomTypeDto) {
        log.info("新增房型:{}", roomTypeDto);
        return BaseResponse.success(roomTypeService.add(roomTypeDto));
    }


    /**
     * 编辑房型
     */
    @PutMapping
    public BaseResponse<Boolean> edit(@RequestBody RoomTypeDto roomTypeDto) {
        log.info("编辑房型:{}", roomTypeDto);
        return BaseResponse.success(roomTypeService.edit(roomTypeDto));
    }

    /**
     * 删除房型
     */
    @DeleteMapping("/{id}")
    public BaseResponse<Boolean> remove(@PathVariable Long id) {
        log.info("删除房型:{}", id);
        return BaseResponse.success(roomTypeService.deleteRoomTypeById(id));
    }

    /**
     * 启用or禁用房型
     */
    @PutMapping("/{id}/status/{status}")
    public BaseResponse<Boolean> remove(@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用or禁用房型:{}, {}", id, status);
        return BaseResponse.success(roomTypeService.enableOrDisable(id, status));
    }
}
